$(function () {
    var itemSel = $.Params.create();
    itemSel.addParams("page", 0);
    itemSel.addParams("rows", rows);


    getData();

    //搜索
    $("#searchBtn").on("click", function () {
        var title = $("#title").val();
        var pTitle = $("#searchVal").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        itemSel.addParams("page", 0);
        if (title != "") {
            itemSel.addParams("title", title);
        } else {
            itemSel.addParams("title", undefined);
        }
        if (pTitle != "") {
            itemSel.addParams("pTitle", pTitle);
        } else {
            itemSel.addParams("pTitle", undefined);
        }
        if (startTime != "") {
            itemSel.addParams("startTime", startTime + " 00:00:00");
        } else {
            itemSel.addParams("startTime", undefined);
        }

        if (endTime != "") {
            itemSel.addParams("endTime", endTime + " 23:59:59");
        } else {
            itemSel.addParams("endTime", undefined);
        }
        getData();
    })

    //数据导出
    $("#expBtn").on("click", function () {
        var url = getAdminIP() + "clickLogs/article/export/3/301?1=1";
        var title = $("#title").val();
        var pTitle = $("#searchVal").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        if (title != "") {
            url += "&title=" + title;
        }
        if (pTitle != "") {
            url += "&pTitle=" + pTitle;
        }
        if (startTime != "") {
            url += "&startTime=" + startTime + " 00:00:00";
        }

        if (endTime != "") {
            url += "&endTime=" + endTime + " 23:59:59";
        }
        window.location.href = url;
    })

    function getData() {
        getPageData("get", itemSel, getAdminIP() + "clickLogs/article/3/301", function (data) {
            if (data.success) {
                var itemClickHtml = "";
                if (data.total > 0) {
                    $.each(data.result, function (i, val) {
                        var name = "";
                        var tel = "";
                        var hospitalName = "";
                        var hospitalOffices = "";
                        var title = "";
                        if (val.article != null) {
                            title = val.article.title;
                        }
                        if (val.member != null) {
                            name = val.member.name;
                            tel = val.member.tel;
                            hospitalName = val.member.hospitalName;
                            hospitalOffices = val.member.hospitalOffices;
                        }

                        itemClickHtml += "<tr role= 'row' class='odd' >" +
                            "<td>" + title + "</td>" +
                            "<td>" + name + "</td>" +
                            "<td>" + tel + "</td>" +
                            "<td>" + hospitalName + "</td>" +
                            "<td>" + hospitalOffices + "</td>" +
                            "<td>" + val.createTime + "</td></tr>";
                    })

                } else {
                    itemClickHtml = "暂无数据";
                }
                $("#listContainer").html(itemClickHtml);
            } else {
                alert(data.msg);
            }
        })
    }
})